<template>
  <div>
    <MyHeader title="购物车案例" ></MyHeader>
    <div class="main"> 
      <!-- 把数据渲染到页面上 -->
      <MyGoods
       v-for="item in list" :key="item.id"
       :good='item'
       ></MyGoods>
    </div>
    <MyFooter :list='list'></MyFooter>
  </div>
</template>

<script>
//引用格组件并完成注册
import MyHeader from "./components/MyHeader";
import MyGoods from "./components/MyGoods";
import MyFooter from "./components/MyFooter";
export default {
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  //接收数据
  data() {
    return {
      list: [],
    };
  },
  //获取数据
  created() {
    this.$axios({
      url: "/api/cart",
    })
      .then((res) => (this.list = res.data.list))
      .catch((err) => console.log(err));
  },
};
</script>

<style>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>